package synchroniztion;

/**
 * @program: Dome
 * @description:
 * @className: Chihuo
 * @author: rjt99999
 * @version: 1.0.0
 * @create: 2020-08-03 10:20
 **/
public class Chihuo extends Thread {


    private Baozi baozi;

    public Chihuo(String name, Baozi baozi) {
        super(name);
        this.baozi = baozi;
    }


    @Override
    public void run() {


        while (true) {
            synchronized (baozi) {

                if (baozi.flag == false) {

                    try {

                        baozi.wait();

                    } catch (InterruptedException e) {


                        e.printStackTrace();
                    }


                }


                System.out.println("已吃完");

                baozi.flag = false;

                baozi.notify();


            }
        }

    }
}
